package com.zzh.lib.recorder.mp3;

import android.media.AudioFormat;
import android.os.Build;

import androidx.annotation.RequiresApi;

/**
 * 录制格式
 */

public enum PCMFormat {
    PCM_8BIT(1, AudioFormat.ENCODING_PCM_8BIT),
    PCM_16BIT(2, AudioFormat.ENCODING_PCM_16BIT),
    @RequiresApi(api = Build.VERSION_CODES.S)
    PCM_32BIT(3, AudioFormat.ENCODING_PCM_32BIT);

    private final int bytesPerFrame;
    private final int audioFormat;

    PCMFormat(int bytesPerFrame, int audioFormat) {
        this.bytesPerFrame = bytesPerFrame;
        this.audioFormat = audioFormat;
    }

    public int getBytesPerFrame() {
        return bytesPerFrame;
    }

    public int getAudioFormat() {
        return audioFormat;
    }

    public static PCMFormat valueOf(int value) {
        switch (value) {
            case 1:
                return PCM_8BIT;
            case 2:
                return PCM_16BIT;
            case 3:
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
                    return PCM_32BIT;
                }
        }
        return PCM_16BIT;
    }
}
